package thread.concurrents;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

public class LockSupportDemo {

  public static void main(String[] args) {

    final Node blocker = new Node();

    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        //线程 wait 状态
        LockSupport.park(blocker);
        System.out.println(Thread.currentThread().getName() + " finished");
      }
    }, "newThreadWhoLockSupportpark");
    thread.start();

    //起一个线程 用来唤醒thread线程
    Thread thread1 = new Thread(new Runnable() {
      @Override
      public void run() {
        while (true) {
          // 终止
          LockSupport.unpark(thread);
          // 终止
          thread.interrupt();

          try {
            TimeUnit.SECONDS.sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    });
    thread1.setDaemon(true);
//    thread1.start();
    System.out.println("end ");
  }

  static class Node {

  }

}
